#!/bin/bash
#
# xMediaServerd        Startup script for the xMediaServer
#
# chkconfig: - 85 15
# description: The xMediaServer is an efficient and extensible  \
#	       server implementing the current HTTP standards.
# processname: xMediaServerd


# Source function library.
. /etc/rc.d/init.d/functions


# Path to the xMediaServerd script, server binary, and short-form for messages.
RETVAL=0
xMediaServerd=/usr/local/sbin/xMediaServer/xMediaServer
prog=xMediaServerd
lockfile=/var/lock/subsys/$prog
STOP_TIMEOUT=${STOP_TIMEOUT-10}

# set server start file des max numbers
# server must start confit at max conenction 65536 / 2 = 32768 ,and max stack memory 10240 KB=10MB
ulimit  -n  65536
ulimit  -s  10240

# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure.  So we just do it the way init scripts
# are expected to behave here.
start() {
        echo -n $"Starting $prog: "
        daemon $xMediaServerd $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}

# When stopping xMediaServerd, a delay (of default 10 second) is required
# before SIGKILLing the xMediaServerd parent; this gives enough time for the
# xMediaServerd parent to SIGKILL any errant children.
stop() {
	echo -n $"Stopping $prog: "
	killproc  -d ${STOP_TIMEOUT} $xMediaServerd
	RETVAL=$?
	echo
	[ $RETVAL = 0 ] && rm -f ${lockfile}
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;; 
  status)
    status $xMediaServerd
	RETVAL=$?
	;;
  restart)
	stop
	start
	;; 
  reload)
	exit 3
	;;
  *)
	echo $"Usage: $prog {start|stop|status|restart}"
	RETVAL=2
esac

exit $RETVAL